﻿<Window x:Class="ReportingManagement.Components.DHIS.DHISDatasetConfiguration"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:GenericTools.Models;assembly=GenericTools"
    xmlns:dhis="clr-namespace:ReportingManagement.Components.DHIS"
    mc:Ignorable="d" Height="640" Width="840" Title="DHIS2 Dataset Configuration"
    d:DesignHeight="400" d:DesignWidth="640" WindowStartupLocation="CenterOwner">
    <Window.Resources>
        <ObjectDataProvider x:Key="reportsProvider" ObjectType="{x:Type local:ModelDataRetriever}" 
                            MethodName="GetReports" IsAsynchronous="True" />
        <ObjectDataProvider x:Key="datasetsProvider" ObjectType="{x:Type dhis:DHISDataBridge}"
                            MethodName="GetAllDataSets" IsAsynchronous="True" />
    </Window.Resources>
    
    <Grid Margin="5">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="2*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="5*"/>
        </Grid.ColumnDefinitions>

        <DockPanel Grid.Row="0"  Background="LightBlue">
            <ListBox x:Name="lstReports" Margin="3" ItemsSource="{Binding Source={StaticResource reportsProvider}}"
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionChanged="ListBox_SelectionChanged">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock TextTrimming="CharacterEllipsis" ToolTip="{Binding Description}">
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0} - {1}">
                                    <Binding Path="RepVersion" />
                                    <Binding Path="ReportName" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </DockPanel>
        <GridSplitter Grid.Column="1" VerticalAlignment="Stretch" Width="3" Margin="3,0,0,0" HorizontalAlignment="Center" />
        
        <Grid x:Name="gridDaataset" Grid.Column="2" Margin="3">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition />
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            
            <DockPanel>
                <Label Content="DHIS2 Dataset" />
                <ComboBox x:Name="cboDatasets" DisplayMemberPath="name" SelectedValuePath="id" 
                          ItemsSource="{Binding Source={StaticResource datasetsProvider}}" 
                          SelectionChanged="cboDatasets_SelectionChanged" 
                          SelectedValue="{Binding DatasetId}"/>
            </DockPanel>
            
            <Label Grid.Row="1" Margin="0,5" Content="Match report indicator/data elements with DHIS2 data elements" />
            <DataGrid x:Name="dataGrid" Grid.Row="2" Margin="0,5,0,10" AutoGenerateColumns="False" 
                      CanUserDeleteRows="False" CanUserAddRows="False" ItemsSource="{Binding DatasetsElementLinks}"
                       AlternationCount="2" AlternatingRowBackground="WhiteSmoke">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Report Indicators" Binding="{Binding Path=ReportDataElement.DataDescription}" />
                    <DataGridComboBoxColumn x:Name="dataGridCboDataElement" Header="DHIS2 Dataset Data Elements" 
                                            SelectedValueBinding="{Binding id}" 
                                            SelectedValuePath="id" DisplayMemberPath="name" />
                </DataGrid.Columns>
            </DataGrid>
            
            <DockPanel Grid.Row="3" LastChildFill="False">
                <DockPanel.Resources>
                    <Style TargetType="{x:Type Button}">
                        <Setter Property="Padding" Value="10,2" />
                        <Setter Property="Margin" Value="10,0,0,0" />
                    </Style>
                </DockPanel.Resources>
                <Button x:Name="btnSave" DockPanel.Dock="Right" Height="24" VerticalAlignment="Top" Click="btnSave_Click">Save Changes</Button>
                <Button x:Name="btnReset" DockPanel.Dock="Right" IsEnabled="False" Click="btnReset_Click">Reset</Button>
            </DockPanel>
        </Grid>
    </Grid>
</Window>
